"use strict"

module.exports = function (grunt) {

  grunt.initConfig({
    // 自动补全
    autoprefixer: {
      options: {
        browsers: [
          'Android 2.3',
          'Android >= 4',
          'Chrome >= 20',
          'Firefox >= 24',
          'Explorer >= 8',
          'iOS >= 6',
          'Opera >= 12',
          'Safari >= 6'
        ]
      },
      core: {
        src: 'css/app.css'
      }
    },

    // 静态服务器
    connect: {
      options: {
        port: 8088,
        hostname: '*',
        livereload: 35729
      },
      core: {
        options: {
          open: true,
          base: '.'
        }
      }
    },

    // css压缩
    cssmin: {
      options: {
        compatibility: 'ie8',
        keepSpecialComments: '*',
        advanced: false
      },
      core: {
        src: 'css/app.css',
        dest: 'css/app.min.css'
      }
    },

    // less解析
    less: {
      core: {
        options: {
          strictMath: true
        },
        src: 'less/*.less',
        dest: 'css/app.css'
      }
    },
    
    // 文件变化监听
    watch: {
      less: {
        options: {
          livereload: '<%=connect.options.livereload%>'
        },

        files: 'less/**/*.less',
        tasks: ['less', 'autoprefixer']
      }
    }
  })

  // 加载包
  grunt.loadNpmTasks('grunt-contrib-watch')// 文件变化监听
  grunt.loadNpmTasks('grunt-contrib-connect')// 静态服务器
  grunt.loadNpmTasks('grunt-contrib-less')// less解析
  grunt.loadNpmTasks('grunt-contrib-cssmin')// css压缩
  grunt.loadNpmTasks('grunt-autoprefixer')// 自动补全

  // 命令
  grunt.registerTask('serve', ['connect', 'watch'])
  grunt.registerTask('build', ['less', 'autoprefixer', 'cssmin'])
}